package org.newcih.controller;

import org.newcih.domain.Order;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.WebAsyncTask;

import java.util.concurrent.Callable;

@Controller
@RequestMapping("async")
public class AsyncController {

    @RequestMapping("response-body")
    @ResponseBody
    public Callable<Order> callable() {
        return () -> {
            Thread.sleep(2000);
            return new Order();
        };
    }

    @RequestMapping("custom-timeout-handling")
    @ResponseBody
    public WebAsyncTask<Order> callableWIthCustomTImeoutHandling() {
        return new WebAsyncTask<Order>(1000, () -> {
            Thread.sleep(2000);
            return new Order();
        });
    }
}
